/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
        if(!headA || !headB)
            return nullptr;   
        struct ListNode* cur1 = headA;
        struct ListNode* cur2 = headB;
        while(cur1 != cur2){
            cur1 = cur1 == nullptr? headB : cur1->next;
            cur2 = cur2 == nullptr? headA : cur2->next;
        }
        return cur1;

    }
};